namespace Mysolution.Domain.Entities.App;

public class AppUser :EntityBase
{
    public string Username {get;set;} =null!;
    public string Password {get;set;} = null!;
    public string Salt {get;set;} =null!;

    public Guid? DepartmentId {get;set;}

    public AppDepartment? Department {get;set;}
    public ICollection<AppRole> Roles {get;set;} =new List<AppRole>();
    
    public void AssignRole(AppRole role)
    {
        if (!Roles.Contains(role))
            Roles.Add(role);
    }

    public void RemoveRole(AppRole role)
    {
        if (Roles.Contains(role))
            Roles.Remove(role);
    }

    public bool HasPermission(string permissionCode)
    {
        return Roles.Any(r => r.HasPermission(permissionCode));
    }
}